//-----------------------------------------------------------------------------
// File: App.h
// Copyright (c) 2005 ATI Technologies Inc. All rights reserved.
//-----------------------------------------------------------------------------





#ifndef _APP_H_
#define _APP_H_

#include "Framework/OpenGL/GLApp.h"
#include "Framework/Util/ProgrammerArt.h"

#define array_size(arr) (sizeof(arr)/sizeof(arr[0]))

void	renderString(const char*	str,vec3&	o,vec3&	u,vec3&	v);

struct Light {
	vec3 position;
	float falloff;
};

//struct VertexVT {
//	vec3 vertex;
	//vec3 normal;
//	vec2 texCoord;
//};

ShaderID	getShader(const char*	path,const char*	defines=null);

class App : public GLApp {
public:
	char *getTitleString(){ return "colony13"; }
	char *getHomeDirectory(){ return "../"; }

	void initGUI();
	void setup(char *args[], int nArguments);
	void resetCamera();

	bool checkFrameBufferStatus();
	bool load();
	bool unload();
	
	void drawLight(const vec3 &lightPos, const vec3 &dx, const vec3 &dy,const float scale=30.0f);
	void drawLightQuad(const vec3 &lightPos, const vec3 &dx, const vec3 &dy,const float scale=30.0f);
	void drawSceneDepth(const vec3 &camPos, const float wx, const float wy);
	void drawScene(const vec3 &camPos, const float wx, const float wy, const Light *lights, const int nLights, const mat4 *shadowMvp = NULL);
	void drawFSQuad();
	void drawFrame();
	void ONIcontrols();

private:
	ShaderID lighting[2][2], depthOnly, sphereEnv, viewDepth;

	Menu *menu;
	MenuItemID render2D, renderCube, renderDepth;

	Model *bunny, *sphere;
public:
	std::vector<vec3>	debugLines;
	std::vector<vec4>	debugColors;
	GLuint fbo2D, fboCube, fboDepth;
	GLuint color2D, colorCube, depth2D, depthBuffer;
	TextureID rtColor2D, rtColorCube, rtDepth2D;
	void	debugLine(vec3&	a,vec3&	b,vec4&	color=vec4(1,1,0,1)){debugLines.push_back(a);debugLines.push_back(b);debugColors.push_back(color);}
	void	debugMarker(vec3&	a,float rad=0.25f,vec4&	color=vec4(1,1,0,1));
	void	debugTransform(vec3&	position,mat3&	rotation=identity3(),float rad=0.5f,vec4&	color=vec4(1,1,0,1));

	TextureID chessBoard, bunnyBase, bunnyBump, lightFlareTexture,sunTexture,titleTexture;
	vec3	screenX;
	vec3	screenY;
	float	blurFactor;
	float	waveGenerators[8];
};

extern App*		gApp;

bool loadModel(const char* fname,Model*	obj);
Model*	loadVertTexIndex(float*	verts,int nverts,float*	tex,int*	index,int nindex,const char*	saveName);
bool loadOBJ(const char* fname,Model*	obj);

#endif
